package com.mg.game.content.gamescreen;

import android.graphics.Canvas;

import com.mg.framework.kernel.CommandEnum;
import com.mg.framework.kernel.ControllerScreen;
import com.mg.framework.tiled.Map;

public class GameScreen extends ControllerScreen {

	private GameBackground gameBackground;
	private TaskMap taskMap;
	private TankManager tankManager;
	private PlayerTank playerTank;

	public GameScreen(int width, int height) {
		super(width, height);
		this.addMoveController();
		this.addOkController();
		this.addMenuController();
		this.gameBackground = new GameBackground(this, this.width, this.height);
		this.taskMap = new TaskMap(this);
	}

	public void setTaskMap(Map map) {
		this.taskMap.setMap(map);
	}

	public void setTankManager(TankManager tankManager) {
		this.tankManager = tankManager;
		this.playerTank = this.tankManager.getPlayerTank();
	}

	@Override
	public void moveNotice(CommandEnum commandState) {
		this.playerTank.executeMoveCommand(commandState);
	}

	@Override
	public void okNotice(CommandEnum commandState) {
		this.playerTank.executeOkCommand(commandState);
	}

	@Override
	public void menuNotice(CommandEnum commandState) {

	}

	@Override
	public void gameUpdate() {
		this.taskMap.gameUpdate();
		// TODO add actors gameUpdate
		this.playerTank.gameUpdate();
		// //////////////////////////
		controllerGameUpdate();
	}

	@Override
	public void screenUpdate(Canvas canvas) {
		this.gameBackground.screenUpdate(canvas);
		this.taskMap.mapUpdate();
		// TODO add actors screenUpdate
		try {
			this.screenUpdateInStage(this.playerTank);
		} catch (Exception e) {
			e.printStackTrace();
		}
		// //////////////////////////
		this.taskMap.screenUpdate(canvas);
		controllerScreenUpdate(canvas);
	}

}
